package com.fr.web.core.upload;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ServletUpload extends HttpServlet
{
  private ServletConfig config;

  public final void init(ServletConfig paramServletConfig)
    throws ServletException
  {
    this.config = paramServletConfig;
  }

  public final ServletConfig getServletConfig()
  {
    return this.config;
  }

  public void doGet(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws ServletException, IOException
  {
    PrintWriter localPrintWriter = paramHttpServletResponse.getWriter();
    localPrintWriter.println("<HTML>");
    localPrintWriter.println("<BODY BGCOLOR='white'>");
    localPrintWriter.println("<H1>jspSmartUpload : Servlet Sample</H1>");
    localPrintWriter.println("<HR><BR>");
    localPrintWriter.println("The method of the HTML form must be POST.");
    localPrintWriter.println("</BODY>");
    localPrintWriter.println("</HTML>");
  }

  protected void doPost(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws ServletException, IOException
  {
    PrintWriter localPrintWriter = paramHttpServletResponse.getWriter();
    localPrintWriter.println("<HTML>");
    localPrintWriter.println("<BODY BGCOLOR='white'>");
    localPrintWriter.println("<H1>jspSmartUpload : Servlet Sample</H1>");
    localPrintWriter.println("<HR>");
    int i = 0;
    SmartUpload localSmartUpload = new SmartUpload();
    try
    {
      localSmartUpload.initialize(this.config, paramHttpServletRequest, paramHttpServletResponse);
      localSmartUpload.upload();
      i = localSmartUpload.save(localSmartUpload.getRequest().getParameter("PATH"));
      localPrintWriter.println(i + " file uploaded.");
    }
    catch (Exception localException)
    {
      localPrintWriter.println("Unable to upload the file.<br>");
      localPrintWriter.println("Error : " + localException.toString());
    }
    localPrintWriter.println("</BODY>");
    localPrintWriter.println("</HTML>");
  }

  public void destroy()
  {
  }
}